package com.seuic.hnjiningposapp.hnapps.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.cardview.widget.CardView;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.base.BaseActivity;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.AutomaticOperationPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DealingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ErrorPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.InputPasswordPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.LiveOnRoSuccessPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.PrintingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ReadCardPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SureLiveOnRotationPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SurePrintPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.VerifyCardPopup;
import com.seuic.hnjiningposapp.hnapps.util.GetMoneyLvUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtilsV2;
import com.seuic.hnjiningposapp.hnapps.util.PrintUtil;
import com.seuic.hnjiningposapp.hnapps.util.TimeUtils;
import com.seuic.posdsdk.pos_func.PosFuncs;
import com.socks.library.KLog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 自助签约
 */
public class SelfHelpContractActivity extends BaseActivity implements ErrorPopup.OnFinishCallbacked, LiveOnRoSuccessPp.CallBackLivetoRoOk, SurePrintPopup.ClickCallback, SureLiveOnRotationPp.onSureLiveOnRo, InputPasswordPopup.ClickCallback {

    private static String MAKE_TYPE = "";//操作类型
    private static final String LIVEON_RO = "LIVEON_RO";//定活自转
    private static final String LIVEON_RO_OPEN = "LIVEON_RO_OPEN";//定活自转解约
    private static final String WEEK = "WEEK";//周周盈签约
    private static final String WEEK_OPEN = "WEEK_OPEN";//周周盈解约


    @BindView(R.id.liveonrotation_btn)
    Button liveonrotationBtn;
    @BindView(R.id.liveonrotation_btn_open)
    Button liveonrotationBtnOpen;
    @BindView(R.id.week_btn)
    Button weekBtn;
    @BindView(R.id.week_open_btn)
    Button weekOpenBtn;
    @BindView(R.id.home_card_layout)
    CardView homeCardLayout;
    private AutomaticOperationPopup automaticOperationPopup;
    private BasePopupView automaticOperationPopupView;
    private BaseActivity baseActivity;
    private ReadCardPopup readcardPop;
    private BasePopupView readcardPopupView;
    private String card_num;
    private VerifyCardPopup verifycardPop;
    private BasePopupView verifycardPopupView;
    private InputPasswordPopup inputpasswordPop;
    private BasePopupView inputpasswordPopupView;
    private SureLiveOnRotationPp sureLiveOnRotationPp;
    private BasePopupView sureLiveOnRotationPpView;
    private DealingPopup dealingPop;
    private BasePopupView dealingPopupView;
    private SurePrintPopup surePrintPop;
    private BasePopupView surePrintPopupView;
    private PrintingPopup printingPop;
    private BasePopupView printingPopupView;
    private LiveOnRoSuccessPp liveOnRoSuccessPp;
    private BasePopupView liveOnRoSuccessPpView;
    private String cipassword;
    private ErrorPopup errorPopup;
    private BasePopupView errorPopupPpView;
    private String card_username;
    private String make_time;
    private String mServerSeqNo;
    private String interest;

    // 功能基数
    private String transAmt;
    //起点金额
    private String fdepAmt;
    //留存金额
    private String balanceLimit;

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_self_help_contract;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        this.setTitleText("自助签约");
        findViewById(R.id.base_back_btn).setVisibility(View.INVISIBLE);
        errorPopup = new ErrorPopup(this, this);
        errorPopupPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(errorPopup);

        liveOnRoSuccessPp = new LiveOnRoSuccessPp(this, this);
        //定活互转成功 界面
        liveOnRoSuccessPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(liveOnRoSuccessPp);
        //打印纸是否正常界面
        surePrintPop = new SurePrintPopup(this, this, this);
        surePrintPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(surePrintPop);
        printingPop = new PrintingPopup(this, this);
        //打印中界面
        printingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(printingPop);
        dealingPop = new DealingPopup(this, this);
        dealingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dealingPop);        //交易中
        sureLiveOnRotationPp = new SureLiveOnRotationPp(this, this);
        sureLiveOnRotationPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(sureLiveOnRotationPp);//确认定活自转数据
        readcardPop = new ReadCardPopup(this);
        //验证账户信息界面
        readcardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(readcardPop);
        verifycardPop = new VerifyCardPopup(this, this);
        //验证账户信息界面
        verifycardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(verifycardPop);
        inputpasswordPop = new InputPasswordPopup(this, this);
        //输入密码界面
        inputpasswordPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(inputpasswordPop);
    }

    @Override
    public void initEvent(Bundle savedInstanceState) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.liveonrotation_btn, R.id.liveonrotation_btn_open, R.id.week_btn, R.id.week_open_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.liveonrotation_btn:
                //定活自转签约
                MAKE_TYPE = LIVEON_RO;

                break;
            case R.id.liveonrotation_btn_open:
                //定活自转解约
                MAKE_TYPE = LIVEON_RO_OPEN;
                break;
            case R.id.week_btn:
                //周周赢签约
                MAKE_TYPE = WEEK;
                break;
            case R.id.week_open_btn:
                //周周赢解约
                MAKE_TYPE = WEEK_OPEN;
                break;
        }
        homeCardLayout.setVisibility(View.GONE);
        readcardstart();//读卡操作
    }

    private void readcardstart() {
        readCard(new HttpUtils.BaseReadCardListener() {
            @Override
            public void onSuccess(String data, String track2Data) {
                card_num = data;
                verifycardPopupView.show();
                HttpUtilsV2.getCheckingThisBank(data, new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                verifycardPopupView.dismiss();
                                KLog.e("进行验证本行卡数据,验证通过,进行输入密码");
                                if (!inputpasswordPopupView.isShow()) {
                                    inputpasswordPopupView.show();
                                }
                            }
                        });

                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });
            }

            @Override
            public void onError(String msg) {
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
//                finish();
            }
        });

    }

    /**
     * 输入密码的回调
     *
     * @param password
     */
    @Override
    public void SendPassword(String password) {
        inputpasswordPopupView.dismiss();
        cipassword = HttpUtils.getResult(password, card_num);
        businessOperation();
    }

    private void businessOperation() {
        //弹出验证消息
        showMakeHint("验证密码...");
        HttpUtilsV2.getAccountPwdVerification(card_num, cipassword, new HttpUtilsV2.NetCallBack() {

            private String sa_blc_amt;

            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                runOnUiThread(() -> {
                    //验证密码成功
                    dismissshowMakeHint();
                    //获取客户信息
                    showMakeHint("获取客户信息...");
                    HttpUtilsV2.getQueryBankCardInfo(card_num, new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            card_username = rspBody.getString("AcctName");
                            runOnUiThread(() -> {
                                dismissshowMakeHint();
                                showMakeHint("黑名单验证...");
                                HttpUtilsV2.getCheckingBankCardBlacklist(card_num, card_username, new HttpUtilsV2.NetCallBack() {
                                    @Override
                                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                        runOnUiThread(() -> {
                                            //黑名单验证通过
                                            dismissshowMakeHint();
                                            showMakeHint("查询签约信息...");
                                            HttpUtilsV2.getSigningInquiry(card_num, new HttpUtilsV2.NetCallBack() {
                                                @Override
                                                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                                    String IsZZYSign = rspBody.getString("IsZZYSign");
                                                    String IsDHZZSign = rspBody.getString("IsDHZZSign");

                                                    //活期留存金额
                                                    String sa_blc_amt = rspBody.getString("SA_BLC_AMT");
                                                    //理财基数
                                                    String TRANS_BAMT = rspBody.getString("TRANS_BAMT");
                                                    //起存金额
                                                    String FS_SA_FDEP_AMT = rspBody.getString("FS_SA_FDEP_AMT");

                                                    runOnUiThread(new Runnable() {
                                                        @Override
                                                        public void run() {
//                                                    Y-是
//                                                    N-否
                                                            if (MAKE_TYPE.equals(LIVEON_RO)) {
                                                                //定活自转签约
                                                                if (IsDHZZSign.equals("N")) {
                                                                    //可以签约
                                                                    if (IsZZYSign.equals("N")) {
                                                                        //可以签约
//                                                                定活自转-888FSC815050100001
//                                                                周周赢- 888FSC815050100002
                                                                        HttpUtilsV2.getSigningDetailsInquiry(
                                                                                "888FSC815050100001",
                                                                                new HttpUtilsV2.NetCallBack() {
                                                                                    @Override
                                                                                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
//                                                                                        留存金额
                                                                                        balanceLimit = rspBody.getString("BalanceLimit");
                                                                                        //起点金额
                                                                                        fdepAmt = rspBody.getString("FdepAmt");
                                                                                        //功能基数
                                                                                        transAmt = rspBody.getString("TransAmt");


                                                                                        runOnUiThread(() -> {
                                                                                            dismissshowMakeHint();
                                                                                            sureLiveOnRotationPpView.show();
                                                                                            sureLiveOnRotationPp.setmBankNum(card_num);
                                                                                            sureLiveOnRotationPp.setmCardInalNum(GetMoneyLvUtils.getMoney(transAmt));
                                                                                            sureLiveOnRotationPp.setmInfotype("定活自转签约");
                                                                                            sureLiveOnRotationPp.setmUpNum(GetMoneyLvUtils.getMoney(fdepAmt));
                                                                                            sureLiveOnRotationPp.setmUserName(card_username);
                                                                                            sureLiveOnRotationPp.setmSaveMoney(GetMoneyLvUtils.getMoney(balanceLimit));
                                                                                        });
                                                                                    }

                                                                                    @Override
                                                                                    public void onError(String code, String msg) {
                                                                                        showErr(msg);
                                                                                    }
                                                                                });
                                                                    } else {
                                                                        //已签约周周盈
                                                                        showErr("您已签约周周盈");
                                                                    }
                                                                } else {
                                                                    //已签约  退出
                                                                    showErr("您已签约定活自转");
                                                                }
                                                            } else if (MAKE_TYPE.equals(LIVEON_RO_OPEN)) {
                                                                //定活自转解约
                                                                if (IsDHZZSign.equals("N")) {
                                                                    //已解约
                                                                    showErr("您未签约定活自转");
                                                                } else {
                                                                    //可以解约
                                                                    HttpUtilsV2.getSigningDetailsInquiry(
                                                                            "888FSC815050100001",
                                                                            new HttpUtilsV2.NetCallBack() {
                                                                                @Override
                                                                                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
//

//                                                                                    留存金额
                                                                                    balanceLimit = rspBody.getString("BalanceLimit");
                                                                                    //起点金额
                                                                                    fdepAmt = rspBody.getString("FdepAmt");
                                                                                    //功能基数
                                                                                    transAmt = rspBody.getString("TransAmt");

                                                                                    runOnUiThread(() -> {
                                                                                        dismissshowMakeHint();
                                                                                        sureLiveOnRotationPpView.show();
                                                                                        sureLiveOnRotationPp.setmBankNum(card_num);
                                                                                        sureLiveOnRotationPp.setmCardInalNum(GetMoneyLvUtils.getMoney(transAmt));
                                                                                        sureLiveOnRotationPp.setmInfotype("定活自转解约");
                                                                                        sureLiveOnRotationPp.setmUpNum(GetMoneyLvUtils.getMoney(fdepAmt));
                                                                                        sureLiveOnRotationPp.setmUserName(card_username);
                                                                                        sureLiveOnRotationPp.setmSaveMoney(GetMoneyLvUtils.getMoney(balanceLimit));
                                                                                    });
                                                                                }

                                                                                @Override
                                                                                public void onError(String code, String msg) {
                                                                                    showErr(msg);
                                                                                }
                                                                            });
                                                                }

                                                            } else if (MAKE_TYPE.equals(WEEK)) {
                                                                //周周盈签约
                                                                if (IsZZYSign.equals("N")) {
                                                                    //可以签约
                                                                    if (IsDHZZSign.equals("N")) {
                                                                        //可以签约
                                                                        HttpUtilsV2.getSigningDetailsInquiry(
                                                                                "888FSC815050100002",
                                                                                new HttpUtilsV2.NetCallBack() {
                                                                                    @Override
                                                                                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
//                                                                                        留存金额
                                                                                        balanceLimit = rspBody.getString("BalanceLimit");
                                                                                        //起点金额
                                                                                        fdepAmt = rspBody.getString("FdepAmt");
                                                                                        //功能基数
                                                                                        transAmt = rspBody.getString("TransAmt");

                                                                                        runOnUiThread(() -> {
                                                                                            dismissshowMakeHint();
                                                                                            sureLiveOnRotationPpView.show();
                                                                                            sureLiveOnRotationPp.setmBankNum(card_num);
                                                                                            sureLiveOnRotationPp.setmCardInalNum(GetMoneyLvUtils.getMoney(transAmt));
                                                                                            sureLiveOnRotationPp.setmInfotype("周周盈签约");
                                                                                            sureLiveOnRotationPp.setmUpNum(GetMoneyLvUtils.getMoney(fdepAmt));
                                                                                            sureLiveOnRotationPp.setmUserName(card_username);
                                                                                            sureLiveOnRotationPp.setmSaveMoney(GetMoneyLvUtils.getMoney(balanceLimit));
                                                                                        });
                                                                                    }

                                                                                    @Override
                                                                                    public void onError(String code, String msg) {
                                                                                        showErr(msg);
                                                                                    }
                                                                                });
                                                                    } else {
                                                                        //可以签约
                                                                        showErr("您已签约定活自转");
                                                                    }
                                                                } else {
                                                                    //不可签约约
                                                                    showErr("您已签约周周盈");
                                                                }
                                                            } else if (MAKE_TYPE.equals(WEEK_OPEN)) {
                                                                //周周盈解约
                                                                if (IsZZYSign.equals("N")) {
                                                                    //可以签约
                                                                    showErr("您未签约周周盈");
                                                                } else {
                                                                    //可以解约
                                                                    HttpUtilsV2.getSigningDetailsInquiry(
                                                                            "888FSC815050100002",
                                                                            new HttpUtilsV2.NetCallBack() {
                                                                                @Override
                                                                                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
//                                                                                    留存金额
                                                                                    balanceLimit = rspBody.getString("BalanceLimit");
                                                                                    //起点金额
                                                                                    fdepAmt = rspBody.getString("FdepAmt");
                                                                                    //功能基数
                                                                                    transAmt = rspBody.getString("TransAmt");

                                                                                    runOnUiThread(() -> {
                                                                                        dismissshowMakeHint();
                                                                                        sureLiveOnRotationPpView.show();
                                                                                        sureLiveOnRotationPp.setmBankNum(card_num);
                                                                                        sureLiveOnRotationPp.setmCardInalNum(GetMoneyLvUtils.getMoney(transAmt));
                                                                                        sureLiveOnRotationPp.setmInfotype("周周盈解约");
                                                                                        sureLiveOnRotationPp.setmUpNum(GetMoneyLvUtils.getMoney(fdepAmt));
                                                                                        sureLiveOnRotationPp.setmUserName(card_username);
                                                                                        sureLiveOnRotationPp.setmSaveMoney(GetMoneyLvUtils.getMoney(balanceLimit));
                                                                                    });
                                                                                }

                                                                                @Override
                                                                                public void onError(String code, String msg) {
                                                                                    showErr(msg);
                                                                                }
                                                                            });
                                                                }
                                                            }
                                                        }
                                                    });
                                                }

                                                @Override
                                                public void onError(String code, String msg) {
                                                    showErr(msg);
                                                }
                                            });

                                        });
                                    }

                                    @Override
                                    public void onError(String code, String msg) {
                                        showErr(msg);
                                    }
                                });
                            });
                        }

                        @Override
                        public void onError(String code, String msg) {
                            showErr(msg);
                        }
                    });
                });
            }

            @Override
            public void onError(String code, String msg) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtils.showLong(msg);
                        dismissshowMakeHint();
                        inputpasswordPopupView = null;
                        inputpasswordPop = null;
                        inputpasswordPop = new InputPasswordPopup(SelfHelpContractActivity.this, SelfHelpContractActivity.this);
                        inputpasswordPopupView = new XPopup.Builder(SelfHelpContractActivity.this)
                                .dismissOnBackPressed(false)
                                .dismissOnTouchOutside(false)
                                .moveUpToKeyboard(false)
                                .isRequestFocus(false)
                                .hasShadowBg(false)
                                .hasStatusBarShadow(false)
                                .asCustom(inputpasswordPop);//
                        inputpasswordPopupView.show();
                    }
                });
            }
        });
    }

    private void showErr(String msg) {
        runOnUiThread(() -> {
            errorPopup.setMsg(msg);
            errorPopupPpView.show();
        });
    }

    /**
     * 确认定活自转信息
     */
    @Override
    public void onCallSureLiveOnro() {
        sureLiveOnRotationPpView.dismiss();
        dealingPopupView.show();
        make_time = TimeUtils.getTimeData();
        if (MAKE_TYPE.equals(LIVEON_RO) || MAKE_TYPE.equals(WEEK)) {
//            定活自转-888FSC815050100001
//                                                                周周赢- 888FSC815050100002
            String prdode = "888FSC815050100001";
            String name = "定活自转签约";
            String code = "200001";
            if (MAKE_TYPE.equals(WEEK)) {
                prdode = "888FSC815050100002";
                name = "周周盈签约";
                code = "200003";
            }
            String finalName = name;
            HttpUtilsV2.getSigningBusinessContract(
                    code,
                    card_num,
                    prdode,
                    transAmt,
                    fdepAmt,
                    balanceLimit,
                    cipassword,
                    new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            mServerSeqNo = ServerSeqNo;
                            runOnUiThread(() -> {
                                dealingPopupView.dismiss();
                                liveOnRoSuccessPp.setmCardNum(card_num);

                                liveOnRoSuccessPp.setmSwName(finalName);
                                liveOnRoSuccessPp.setmUserName(card_username);
                                liveOnRoSuccessPpView.show();
                            });
                        }

                        @Override
                        public void onError(String code, String msg) {
                            showErr(msg);
                        }
                    });
        } else if (MAKE_TYPE.equals(LIVEON_RO_OPEN) || MAKE_TYPE.equals(WEEK_OPEN)) {

            String code = "200002";
            if (MAKE_TYPE.equals(WEEK_OPEN)) {
                code = "200004";
            }
            //解约
            HttpUtilsV2.getSigningBusinessTermination(
                    code,
                    card_num,
                    cipassword,
                    new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mServerSeqNo = ServerSeqNo;
                                    interest = rspBody.getString("Interest");
                                    dealingPopupView.dismiss();
                                    liveOnRoSuccessPp.setmCardNum(card_num);
                                    if (MAKE_TYPE.equals(LIVEON_RO_OPEN)) {
                                        liveOnRoSuccessPp.setmSwName("定活自转解约");
                                    } else {
                                        liveOnRoSuccessPp.setmSwName("周周盈解约");
                                    }
                                    liveOnRoSuccessPp.setmUserName(card_username);
                                    sureLiveOnRotationPpView.dismiss();
                                    liveOnRoSuccessPpView.show();
                                }
                            });

                        }

                        @Override
                        public void onError(String code, String msg) {
                            showErr(msg);
                        }
                    });


        }
    }

    /**
     * 确定打印纸安装正常 开始打印
     */
    @Override
    public void ToPrint() {
        surePrintPopupView.dismiss();
        printingPopupView.show();
        HttpUtilsV2.getElectronicSeal("1", new HttpUtilsV2.NetCallBack() {
            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                if (MAKE_TYPE.equals(LIVEON_RO) || MAKE_TYPE.equals(WEEK)) {
                    //如果是定活自转 或者周周盈签约
                    String name = "定活自转签约";
                    if (MAKE_TYPE.equals(WEEK)) {
                        name = "周周盈签约";
                    }
                    String finalName = name;
                    PrintUtil.dhSelfSingOrWeekSing(PosFuncs.getInstace()
                            , make_time
                            , name
                            , mServerSeqNo
                            , card_username
                            , card_num
                            , GetMoneyLvUtils.getMoney(balanceLimit)
                            , GetMoneyLvUtils.getMoney(fdepAmt)
                            , GetMoneyLvUtils.getMoney(transAmt)
                            , rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                @Override
                                public void success(String success) {
                                    PrintUtil.dhSelfSingOrWeekSing2(PosFuncs.getInstace()
                                            , make_time
                                            , finalName
                                            , mServerSeqNo
                                            , card_username
                                            , card_num
                                            , GetMoneyLvUtils.getMoney(balanceLimit)
                                            , GetMoneyLvUtils.getMoney(fdepAmt)
                                            , GetMoneyLvUtils.getMoney(transAmt)
                                            , rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                                @Override
                                                public void success(String success) {
                                                    ToastUtils.showLong(success);
                                                    SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                    finish();
                                                }

                                                @Override
                                                public void failed(String error) {
                                                    showErr(error);
                                                }
                                            });
                                }

                                @Override
                                public void failed(String error) {
                                    showErr(error);
                                }
                            });
                } else {
                    //如果是解约
                    String maketype = "";
                    if (MAKE_TYPE.equals(LIVEON_RO_OPEN)) {
                        maketype = "定活自转解约";
                    } else {
                        maketype = "周周盈解约";
                    }
                    String finalMaketype = maketype;
                    PrintUtil.dhSelfOpenOrWeekOpen(PosFuncs.getInstace()
                            , make_time
                            , maketype
                            , mServerSeqNo
                            , card_username
                            , card_num
                            , GetMoneyLvUtils.getMoney(interest)
                            , GetMoneyLvUtils.getMoney(balanceLimit)
                            , GetMoneyLvUtils.getMoney(fdepAmt)
                            , GetMoneyLvUtils.getMoney(transAmt)
                            , rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                @Override
                                public void success(String success) {
                                    PrintUtil.dhSelfOpenOrWeekOpen2(PosFuncs.getInstace()
                                            , make_time
                                            , finalMaketype
                                            , mServerSeqNo
                                            , card_username
                                            , card_num
                                            , GetMoneyLvUtils.getMoney(interest)
                                            , GetMoneyLvUtils.getMoney(balanceLimit)
                                            , GetMoneyLvUtils.getMoney(fdepAmt)
                                            , GetMoneyLvUtils.getMoney(transAmt)
                                            , rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                                @Override
                                                public void success(String success) {
                                                    ToastUtils.showLong(success);
                                                    SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                    finish();
                                                }

                                                @Override
                                                public void failed(String error) {
                                                    showErr(error);
                                                }
                                            });
                                }

                                @Override
                                public void failed(String error) {
                                    showErr(error);
                                }
                            });
                }
            }

            @Override
            public void onError(String code, String msg) {
                showErr(msg);
            }
        });

    }

    /**
     * 定活自转 签月解约 成功界面点击了确认
     */
    @Override
    public void LivetoRoOk() {
        liveOnRoSuccessPpView.dismiss();
        surePrintPopupView.show();
    }

    @Override
    public void finished() {
        finish();
    }
}
